package top.malaoshi.netdisk.ctrl;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.malaoshi.netdisk.service.NoteTypeSrvImpl;
import top.malaoshi.netdisk.vo.JsonResult;
import top.malaoshi.netdisk.vo.NoteType;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/noteType")
@Validated
public class NoteTypeCtrl {

    @Resource
    private NoteTypeSrvImpl noteTypeSrv;

    @GetMapping("/list")
    public JsonResult list() throws Exception {

        List list = noteTypeSrv.query();

        return JsonResult.success(null,list);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody @Valid NoteType noteType) throws Exception {
        noteTypeSrv.save(noteType);
        return JsonResult.success("添加成功！");
    }
    @PostMapping("/update")
    @Validated
    public JsonResult updateById(@RequestBody @Valid NoteType noteType) throws Exception {

        noteTypeSrv.updateById(noteType);

        return JsonResult.success("修改成功！");
    }
    @GetMapping("/recycle")
    public JsonResult recycleById(String id) throws Exception {

        JsonResult jr = noteTypeSrv.recycleById(id);

        return jr;
    }
    @GetMapping("/delete")
    public JsonResult deleteById(String id) throws Exception {

        noteTypeSrv.deleteById(id);

        return JsonResult.success("删除成功！");
    }
}
